import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/data/request/organization_request.dart';
import 'package:bxultimate/data/store/auth_store.dart';
import 'package:bxultimate/shared/shared.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'state.dart';

class ApplicationIndexController extends GetxController
    with GetSingleTickerProviderStateMixin {
  final ApplicationIndexState state = ApplicationIndexState();

  TabController? tabController;

  TextEditingController conditionController = TextEditingController();

  var tabItem = ['我的组织','我的申请','推荐组织'];

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    tabController = TabController(length: tabItem.length, vsync: this);

    getData();
  }

  void getData() async {
    String devicePosition =
        UtilSp.getString(AppConstant.DEVICE_POSITION, defValue: '')!;
    var position = devicePosition.split(",");
    if(position.length > 1 && AuthStore.to.isLogin){
      state.recommandList = await OrganizationRequest.recommendationTeam(
          position[0], position[1], conditionController.text);
    }

  }

  void toOrganizationCreate() {
    Get.toNamed(RouterName.organizationCreate);
  }
}
